package com.ahp.service.impl;

import java.util.List;

import org.springframework.transaction.annotation.Transactional;

import com.ahp.bean.Tast;
import com.ahp.bean.User;
import com.ahp.dao.TaskDao;
import com.ahp.dao.UserDao;
import com.ahp.service.TaskService;

public class TaskServiceImpl implements TaskService {
	private TaskDao taskDao;
	private UserDao userDao;

	public TaskDao getTaskDao() {
		return taskDao;
	}

	public void setTaskDao(TaskDao taskDao) {
		this.taskDao = taskDao;
	}

	public UserDao getUserDao() {
		return userDao;
	}

	public void setUserDao(UserDao userDao) {
		this.userDao = userDao;
	}

	/* (non-Javadoc)
	 * @see com.ahp.service.TaskService#addTask()
	 */
	public Integer addTask(Tast task) {
		Integer m = (Integer)taskDao.save(task);
		return m ;
	}
	
	/* (non-Javadoc)
	 * @see com.ahp.service.TaskService#getMyTasks(java.lang.Integer)
	 */
	public List<Tast> getMyTasks(Integer userId) {
		String hql = "from Tast t where t.user.id="+userId;
		return taskDao.find(hql);
	}
	
	/* (non-Javadoc)
	 * @see com.ahp.service.TaskService#delNotHasScoreTask(com.ahp.bean.User)
	 */
	public void delNotHasScoreTask(User user) {
		/*user = (User)userDao.get(User.class, user.getId());
		Set<Tast> tastSet = user.getTasts();
		Set<Tast> newTastSet = new HashSet<Tast>();
		System.out.println("tastSet.size():"+tastSet.size());
		for (Tast tast : tastSet) {
			if(!(tast.getEvaleObject()==null || tast.getEvaleObject().isEmpty())){
				newTastSet.add(tast);
			}
			Set<EvaleObject> objSet = tast.getEvaleObject();
			System.out.println("objSet.size():"+objSet.size());
			
			Set<EvaleObject> newObjSet = new HashSet<EvaleObject>();
			for (EvaleObject evaleObject : objSet) {
				System.out.println(evaleObject.getScore());
				if(!(evaleObject == null )){
					newObjSet.add(evaleObject);
				}
			}
		}
		
		userDao.flush();
		userDao.update(user);*/
	}

	public void delTask(Tast task) {
		task = taskDao.get(Tast.class, task.getTastId());
		taskDao.delete(task);
	}
}
